﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreEx.Database.Client;
using LinFu.IoC.Configuration;
using LinFu.IoC.Interfaces;
using LinFu.IoC;

namespace CoreEx.Database.Linq.Implementation
{
    [Factory(typeof(IQueryTranslator))]
    public class ExpressionTranslatorFactory : IFactory<IQueryTranslator>
    {
        public IQueryTranslator CreateInstance(IFactoryRequest request)
        {
            var connectionName = request.ServiceName;
            if (string.IsNullOrEmpty(connectionName))            
                connectionName = request.Container.GetService<DbConnectionInfo>().Name;

            var expressionTranslator = new QueryTranslator(connectionName);
            return expressionTranslator;
        }
    }
}
